/* === LICENSE INFO ===
 * This source file is subject to the GPLv3 license that is bundled with this
 * package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl.txt
 * === end of LICENSE INFO === */

/*==============================================================================
  File Name   : main.cpp
  Description : Test driver for GDateTime module.

  Created on  : 2009-11-04
  Updated on  : 2011-02-04
  Updated by  : Lee Shiou Ming

  Cautions    : (important notes)
  ============================================================================*/

//------------------------------------------------------------------------------
//-- INCLUDES & DEFINES
//------------------------------------------------------------------------------
#include "GDateTime/GDateTime.hpp"
#include <iostream>
#include <stdexcept>


//------------------------------------------------------------------------------
//-- TYPEDEF / STRUCT / UNION / ENUM
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
//-- GLOBAL
//------------------------------------------------------------------------------
const std::string g_AppName       = "Test driver";
const std::string g_AppVersion    = "1.0.4.11";
const std::string g_ModuleName    = "GDateTime module";
const std::string g_ModuleVersion = "1.0.5.11";


//------------------------------------------------------------------------------
//-- FUNCTION PROTOTYPES
//------------------------------------------------------------------------------
void testDateTimeString();
void testSpecifiedDateTimeString();
void testDateString();
void testSpecifiedDateString();
void testTimeString();
void testSpecifiedTimeString();


//------------------------------------------------------------------------------
//-- MAIN FUNCTION
//------------------------------------------------------------------------------
int main(int _argc, char* _argv[])
{
    std::cout << std::endl << "======" << std::endl;
    std::cout << g_AppName.c_str() << ", version " << g_AppVersion.c_str();
    std::cout << std::endl << "for " << g_ModuleName.c_str() <<
        ", version " << g_ModuleVersion.c_str();
    std::cout << std::endl << "======" << std::endl << std::endl;


    try
    {
        testDateTimeString();
        testSpecifiedDateTimeString();
        testDateString();
        testSpecifiedDateString();
        testTimeString();
        testSpecifiedTimeString();
    }
    catch (std::exception& e)
    {
        std::cerr << "[EMERGENCY] main(): " << e.what() << std::endl;
    }
    catch (...)
    {
        std::cerr << "[EMERGENCY] main(): Unknown exception detected." <<
                std::endl;
    }


    //-- Stop the console screen before quit for displaying the output.
    std::cout << std::endl << std::endl << "Press <ENTER> key to exit";
    std::cin.get();

    return 0;
}


//------------------------------------------------------------------------------
//-- FUNCTION IMPLEMENTATIONS
//------------------------------------------------------------------------------
// Test description:
// 1. Call the gUtil::GDateTime::getDateTimeString() function.
// Expected behavior:
// 1. A string will be return with current date time in ISO format, with vary
//    precision depends on parameter (refer to function description in header
//    file).
void testDateTimeString()
{
    using namespace gUtil;

    std::cout << std::endl << "----" << __FUNCTION__ << std::endl;

    std::cout << "getDateTimeString(): " <<
            GDateTime::getDateTimeString() <<
            std::endl;

    std::cout << "getDateTimeString(GDateTime::PRECISION_SECOND): " <<
            GDateTime::getDateTimeString(GDateTime::PRECISION_SECOND) <<
            std::endl;

    std::cout << "getDateTimeString(GDateTime::PRECISION_MILLESECOND): " <<
            GDateTime::getDateTimeString(GDateTime::PRECISION_MILLESECOND) <<
            std::endl;

    std::cout << "getDateTimeString(GDateTime::PRECISION_MICROSECOND): " <<
            GDateTime::getDateTimeString(GDateTime::PRECISION_MICROSECOND) <<
            std::endl;
}


// Test description:
// 1. Call the gUtil::GDateTime::getDateTimeString() function with date time
//    specified in parameter.
// Expected behavior:
// 1. A string will be return with date time specified by parameter, output in
//    ISO format, with vary precision depends on parameter (refer to function
//    description in header file).
void testSpecifiedDateTimeString()
{
    using namespace gUtil;

    std::cout << std::endl << "----" << __FUNCTION__ << std::endl;

    GDateTime::ptime now = GDateTime::getCurrentTime();

    std::cout << "getDateTimeString(GDateTime::ptime): " <<
            GDateTime::getDateTimeString(now) <<
            std::endl;

    std::cout << "getDateTimeString(GDateTime::ptime, GDateTime::PRECISION_SECOND): " <<
            GDateTime::getDateTimeString(now, GDateTime::PRECISION_SECOND) <<
            std::endl;

    std::cout << "getDateTimeString(GDateTime::ptime, GDateTime::PRECISION_MILLESECOND): " <<
            GDateTime::getDateTimeString(now, GDateTime::PRECISION_MILLESECOND) <<
            std::endl;

    std::cout << "getDateTimeString(GDateTime::ptime, GDateTime::PRECISION_MICROSECOND): " <<
            GDateTime::getDateTimeString(now, GDateTime::PRECISION_MICROSECOND) <<
            std::endl;
}


// Test description:
// 1. Call the gUtil::GDateTime::getDateString() function.
// Expected behavior:
// 1. A string will be return with current date in ISO format, depends on
//    parameter (refer to function description in header file).
void testDateString()
{
    using namespace gUtil;

    std::cout << std::endl << "----" << __FUNCTION__ << std::endl;

    std::cout << "getDateString(): " <<
            GDateTime::getDateString() << std::endl;

    std::cout << "getDateString(true): " <<
            GDateTime::getDateString(true) << std::endl;

    std::cout << "getDateString(false): " <<
            GDateTime::getDateString(false) << std::endl;
}


// Test description:
// 1. Call the gUtil::GDateTime::getDateString() function with date specified in
//    parameter.
// Expected behavior:
// 1. A string will be return with date specified by parameter output in
//    ISO format, depends on parameter (refer to function description in header
//    file).
void testSpecifiedDateString()
{
    using namespace gUtil;

    std::cout << std::endl << "----" << __FUNCTION__ << std::endl;

    GDateTime::ptime now = GDateTime::getCurrentTime();

    std::cout << "getDateString(GDateTime::ptime): " <<
            GDateTime::getDateString(now) << std::endl;

    std::cout << "getDateString(GDateTime::ptime, true): " <<
            GDateTime::getDateString(now, true) << std::endl;

    std::cout << "getDateString(GDateTime::ptime, false): " <<
            GDateTime::getDateString(now, false) << std::endl;
}


// Test description:
// 1. Call the gUtil::GDateTime::getTimeString() function.
// Expected behavior:
// 1. A string will be return with current time, which output is configurable
//    via parameters (refer to function description in header file).
void testTimeString()
{
    using namespace gUtil;

    std::cout << std::endl << "----" << __FUNCTION__ << std::endl;

    std::cout << "getTimeString(): " <<
            GDateTime::getTimeString() <<
            std::endl;

    std::cout << "getTimeString(GDateTime::PRECISION_SECOND, true): " <<
            GDateTime::getTimeString(GDateTime::PRECISION_SECOND, true) <<
            std::endl;

    std::cout << "getTimeString(GDateTime::PRECISION_SECOND, false): " <<
            GDateTime::getTimeString(GDateTime::PRECISION_SECOND, false) <<
            std::endl;

    std::cout << "getTimeString(GDateTime::PRECISION_MILLESECOND, true): " <<
            GDateTime::getTimeString(GDateTime::PRECISION_MILLESECOND, true) <<
            std::endl;

    std::cout << "getTimeString(GDateTime::PRECISION_MILLESECOND, false): " <<
            GDateTime::getTimeString(GDateTime::PRECISION_MILLESECOND, false) <<
            std::endl;

    std::cout << "getTimeString(GDateTime::PRECISION_MICROSECOND, true): " <<
            GDateTime::getTimeString(GDateTime::PRECISION_MICROSECOND, true) <<
            std::endl;

    std::cout << "getTimeString(GDateTime::PRECISION_MICROSECOND, false): " <<
            GDateTime::getTimeString(GDateTime::PRECISION_MICROSECOND, false) <<
            std::endl;
}


// Test description:
// 1. Call the gUtil::GDateTime::getTimeString() function with time specied in
//    parameter.
// Expected behavior:
// 1. A string will be return with time specified by parameter, which output is
//    configurable via other parameters (refer to function description in header
//    file).
void testSpecifiedTimeString()
{
    using namespace gUtil;

    std::cout << std::endl << "----" << __FUNCTION__ << std::endl;

    GDateTime::ptime now = GDateTime::getCurrentTime();

    std::cout << "getTimeString(GDateTime::ptime): " <<
            GDateTime::getTimeString(now) <<
            std::endl;

    std::cout << "getTimeString(GDateTime::ptime, GDateTime::PRECISION_SECOND, true): " <<
            GDateTime::getTimeString(now, GDateTime::PRECISION_SECOND, true) <<
            std::endl;

    std::cout << "getTimeString(GDateTime::ptime, GDateTime::PRECISION_SECOND, false): " <<
            GDateTime::getTimeString(now, GDateTime::PRECISION_SECOND, false) <<
            std::endl;

    std::cout << "getTimeString(GDateTime::ptime, GDateTime::PRECISION_MILLESECOND, true): " <<
            GDateTime::getTimeString(now, GDateTime::PRECISION_MILLESECOND, true) <<
            std::endl;

    std::cout << "getTimeString(GDateTime::ptime, GDateTime::PRECISION_MILLESECOND, false): " <<
            GDateTime::getTimeString(now, GDateTime::PRECISION_MILLESECOND, false) <<
            std::endl;

    std::cout << "getTimeString(GDateTime::ptime, GDateTime::PRECISION_MICROSECOND, true): " <<
            GDateTime::getTimeString(now, GDateTime::PRECISION_MICROSECOND, true) <<
            std::endl;

    std::cout << "getTimeString(GDateTime::ptime, GDateTime::PRECISION_MICROSECOND, false): " <<
            GDateTime::getTimeString(now, GDateTime::PRECISION_MICROSECOND, false) <<
            std::endl;
}
